#include <STC15F2K60S2.H>
#include <key_board.h>
bit xun;
unsigned char key_word;
unsigned char ter;
void Timer0Init(void);
void display(void);
unsigned char dspcom ;
unsigned char re_date;
code unsigned char tab[] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xFF};
unsigned char dspbuf[8] = {10,10,10,10,10,10,10,10};  //?????
void main()
{
	Timer0Init();
	while(1)
	{
		if(xun)
		{
			xun=0;
		 re_date = key_board();
	   dspbuf[7] =  re_date%10;
	   dspbuf[6] =  re_date/10;
    	   
		}
  }
}


void Timer0Init(void)		//1??@12.000MHz
{
	AUXR |= 0x80;		//?????1T??
	TMOD &= 0xF0;		//???????
	TL0 = 0x20;		//??????
	TH0 = 0xD1;		//??????
	TF0 = 0;		
	ET0 = 1;
	EA  = 1;//
	TR0 = 1;		//???0????
}


void timer_irs(void) interrupt 1
{
	if(++ter==5)
	{
		xun=1;
	}
	display();
} 


 void display(void)
{   

	//xiao yin
	P2 = ((P2&0x1f)|0xE0);
	P0 = 0xff;
	P2 &= 0x1f;

	//wei xuan
	P2 = ((P2&0x1f)|0xC0); 
	P0 = 1<<dspcom;
	P2 &= 0x1f;

	//duan xuan
  P2 = ((P2&0x1f)|0xE0);
	P0 = tab[dspbuf[dspcom]];	
	P2 &= 0x1f;
  
  if(++dspcom == 8)
	{
        dspcom = 0;
      }    
}

 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 